import com.modestmaps.*;
import com.modestmaps.core.*;
import com.modestmaps.geo.*;
import com.modestmaps.providers.*;

import java.util.*;
import java.io.*;

/** __system__ variable **/
boolean __loaded__;
int __progress__;

long __dt__;
long __t0__;

PFont _font;

/** DataParser **/
DataParser dp;

/** Entities **/
Application app;
GraphScatter scatterGraph;

InteractiveMap map;
VModestMap vm;
TagCloud tagcloud;

////DropBox parameters//////////////////////////
color GUI_FILL_COLOR = color ( 30, 30, 30);
int GUI_TRANSPARENTCY = 150;

PFont font;
int FONT_SIZE = 12;
color TEXT_FILL_COLOR = color ( 255 );
String currentType = "";

DropBox dbox;
GraphLine sitecomp;
/////////////////////////////////////////////////


Date startDate;

void setup()
{

  __loaded__ = false;
  __progress__ = 0;
  size(APP_WIDTH, APP_HEIGHT);

  /** Font used  **/
  _font = createFont("Helvetica", GRAPH_FONT_SIZE);

 
  // enable the mouse wheel, for zooming
  addMouseWheelListener( new java.awt.event.MouseWheelListener() 
    {
      public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) 
      {
        mouseWheel( evt.getWheelRotation() );
      }
    }
  );
  
  font = createFont("Helvetica", FONT_SIZE);
  textFont(font, FONT_SIZE);
  
  dbox = new DropBox(20,20,350);
}


void draw()
{
  //__t0__ = millis();

  background(APP_BG_CLR);
  if(!__loaded__)
  {
    textFont(_font, 32);
    text("LOADING...",APP_WIDTH/2 - 100,APP_HEIGHT/2);
    __progress__ = LoadApp();
    __loaded__ = true;

    //dp.printInfo();
  }
  /** If Loaded **/
  else
  {
    /** Synchronus Functions **/
    Update();
    Render();
  }

  //__dt__ = millis() - __t0__;
  //println("dt:" + __dt__);  
  
  dbox.render();
}

int LoadApp()
{

  int progress;

  app = new Application();

  /** First Set the data **/
  dp = new DataParser(); 

  /** Instanciate the graph **/
  scatterGraph = new GraphScatter(dp.sitesByTimeMap, 0, 100, APP_WIDTH, APP_HEIGHT-100);
  scatterGraph.setGraphTitle("Text1");
  scatterGraph.setGraphInfo("Text2");

  map = new com.modestmaps.InteractiveMap(this, new Microsoft.HybridProvider());         
  map.setCenterZoom(new com.modestmaps.geo.Location(38, -97), 4);
  vm = new VModestMap(map);
  //vm.setup();
  //vm.addSite("www.uic.edu");
  tagcloud = new TagCloud(dp.siteInfoMap);
  sitecomp = new GraphLine(dp.sitesByTimeMap, dp.siteInfoMap, 0, 100, APP_WIDTH, APP_HEIGHT-100);
  
  return 100;
}

void Update ()
{

}

void Render ()
{

  smooth();
  switch(app.__selected__)
  {
  case GRAPH1:
    scatterGraph.draw(); 
    break;
  case GRAPH2:
    sitecomp.draw();
    break;
  case GRAPH3:
    map.draw();
    vm.setup();
    vm.draw();
    break;
    
  case GRAPH4:
    tagcloud.draw();
    break;
    
  default:

  }
  
  app.draw();
}


void mousePressed()
{
  switch(app.__selected__)
  {
  case GRAPH1:
    {
      scatterGraph.mousePressed();
    }
    break;
  case GRAPH2:
    {
      sitecomp.mousePressed();
    }
    break;
    

  case GRAPH3:
    {
      vm.mousePressed();
    }
    break;
    
    default:
    {
      //nothin
    }
  }
}

void mouseDragged()
{
  switch(app.__selected__)
  {
  case GRAPH1:
    {
      scatterGraph.mouseDragged();
    }
    break;
  case GRAPH2:
    {
      sitecomp.mouseDragged();
    }
    break;  

  case GRAPH3:
    {
      vm.mouseDragged();
    }
    break;
    
    default:
    {
      //nothin
    }
  }
}

void mouseMoved() 
{
  app.mouseOver();
  switch(app.__selected__)
  {
    case GRAPH1:
    if(scatterGraph.PointerInBounds(mouseX, mouseY))
    {
      scatterGraph.mouseOver();
    }
    break;
    case GRAPH2:
    if(sitecomp.PointerInBounds(mouseX, mouseY))
    {
      sitecomp.mouseOver();
    }
    break;
  }
}

void mouseClicked()
{
  app.mouseClicked();
  dbox.processClick();
  switch(app.__selected__)
  {
  case GRAPH1:
    {
      scatterGraph.mouseClicked();
    }
    break;
  case GRAPH2:
    {
      sitecomp.mouseClicked();
    }
    break;

  case GRAPH3:
    {
      vm.mouseClicked();
    }
    break;
    
    default:
    {
      //nothin
    }
  }
}

void mouseWheel(int delta) 
{
  scatterGraph.mouseWheel(delta);
  vm.mouseWheel(delta);
  sitecomp.mouseWheel(delta);
}

void keyPressed() 
{
  sitecomp.keyPressed();
  dbox.processKey();
  scatterGraph.keyPressed();
}

